import React, { Component } from 'react';
import { connect } from 'dva';
import { Link, routerRedux } from 'dva/router';
import {
    WhiteSpace,
    WingBlank,
    Flex,
    Icon,
    ListView,
    Button,
    Modal
} from 'antd-mobile';
import Moment from 'moment';
import NoLazyImg from "../../components/NoLazyImg/NoLazyImg";
import yellowJindu from "../../assets/svg/yellowJindu.svg";
import rightsvg from "../../assets/img/right.svg";
import {Toast} from "antd-mobile/lib/index";
import {tishi,group} from "../find/findIndex.less";

class CollageGroupItem extends Component {
    constructor(props) {
        super(props);
        this.timer = null;
        const {v,goodsDetailInfo} = this.props;
        this.state = {
            d:"",
            showHour:"",
            m:"",
            s:"",
            D:"",
            ShowHour:"",
            M:"",
            S:"",
            now:goodsDetailInfo.nowTime,
            modal:false
        }
    }
    componentDidMount(){
        setInterval(this.countTime, 1000, 1000)
        this.countTime()
    }
    startTime = (time)=>{
        let seconds = parseInt(time / 1000);
        // 总的小时数
        let h = Math.floor(seconds / 60 / 60);
        // 天数
        let d = parseInt(h / 24);
        // 显示的小时数
        let showHour = Math.floor(h - d * 24);
        let m = Math.floor((seconds - h * 60 * 60) / 60);
        let s = Math.floor((seconds - h * 60 * 60 - m * 60));
        if (seconds < 0) {
            h = '0';
            m = '00';
            s = '00';
            d = '00';
            showHour = '00';
        }
        return `${showHour}:${m}`
    }
    Time=(a)=>{
        let seconds = parseInt(a/1000);
        // 总的小时数
        let h = Math.floor(seconds / 60 / 60);
        return h
    }
    countTime=()=>{
        //获取当前时间
        const {v} = this.props;
        var now = this.state.now;
        //设置截止时间
        var end = v.endTime;
        var start = v.startTime;
        let seconds = start>now?parseInt((start - now) / 1000):parseInt((end - now) / 1000);
        // 总的小时数
        let h = Math.floor(seconds / 60 / 60);
        // 天数
        let d = parseInt(h / 24);
        // 显示的小时数
        let showHour = Math.floor(h - d * 24);
        let m = Math.floor((seconds - h * 60 * 60) / 60);
        let s = Math.floor((seconds - h * 60 * 60 - m * 60));
        if (seconds < 0) {
            m = '00';
            s = '00';
            d = '00';
            showHour = '00';
        }
        this.setState({
            d:d,
            showHour:showHour,
            m:m,
            s:s,
            now:now+1000
        })
    };
    render() {
        const {v,key,length,smallGroupDetailList} = this.props;

        const {d,showHour,m,s,D,ShowHour,M,S}=this.state;
        return <Flex  justify="between" style={key==0&&length>1?{borderBottom:"1px solid #EBEBEB",width:"100%"}:{width:"100%"}}>
            <Flex >
                <div style={{width:".78rem",height:".78rem",borderRadius:"100%",marginRight:".2rem"}}>
                    <NoLazyImg src={v.leaderAvatar} style={{width:".78rem",height:'.78rem'}}></NoLazyImg>
                </div>

                <div>{v.leaderName}</div>
            </Flex>
            <Flex >
                <div>
                    <div>还差 <span style={{color:"#FE0A3E"}}>{v.surplusNum}</span> 人拼成</div>
                    <div style={{color:"#999999",marginTop:".1rem"}}>
                        剩余
                        <span>{showHour<10?"0"+showHour:showHour}</span>  :
                        <span>{m<10?"0"+m:m}</span>:
                        <span>{s<10?"0"+s:s}</span>
                    </div>
                </div>
                <div style={{background:"#FE0A3E",color:"#fff",borderRadius:".3rem",padding:".1rem .15rem",marginLeft:".2rem"}} onClick={()=>{this.props.showModal(v)}}>参与拼团</div>
            </Flex>
        </Flex>

    }
}

export default connect(({ goodsDetail }) => ({ goodsDetail }))(CollageGroupItem);